<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>公交查询</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/all_css.css" />
		<link rel="stylesheet" type="text/css" href="css/weui/base.css" />
		<link rel="stylesheet" type="text/css" href="lib/weui.css" />
		<link rel="stylesheet" type="text/css" href="css/weui/jquery-weui.css" />
		<link rel="stylesheet" type="text/css" href="iconfont/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="css/bus.css" />
		<link rel="stylesheet" type="text/css" href="css/loading_icon.css" />
		<style type="text/css">
			/*input框里的两个选择按钮*/
			
			.btnInInput {
				width: 50%;
				height: 80%;
				line-height: 40px;
				display: block;
				float: left;
				text-align: center;
				padding-right: 12px;
				color: #0BB501;
				height: 90%;
				font-size: 1.2em;
			}
			
			.btnInInput img {
				height: 100%;
				vertical-align: middle;
			}
			
			.btnInInput:first-child {
				border-right: 1px dashed #CDCDCD;
				color: #FFB500;
			}
			
			.btnInInput:first-child img {
				width: 27%;
				height: 90%;
			}
			
			.btnInInput:nth-child(2) img {
				width: 37%;
				height: 90%;
				position: relative;
				left: 7px;
			}
			/*底部*/
			
			footer {
				height: 50px;
				background-color: #F5F5F5;
			}
			
			footer li {
				width: 50%;
				margin-top: -1px;
			}
			
			footer img {
				vertical-align: middle;
				margin-top: -6px;
			}
			
			footer label {
				color: #777777;
				font-size: 1.2em;
			}
			
			.chooseMapOrMsg {
				color: #4D98DD;
			}
			
			.BMap_pop>img {
				display: none;
			}
			
			.lineStyle {
				border: 1px solid #FFB500 !important;
			}
			
			.lineStyle .iconfont {
				color: #FFB500 !important;
			}
			
			.stopStyle {
				border: 1px solid #0BB501 !important;
			}
			
			.stopStyle .iconfont {
				color: #0BB501 !important;
			}
			
			.BMap_bubble_content img,
			#infoWndPano {
				display: none;
			}
			/*到这去按钮*/
			
			#goHearBtn {
				width: 35%;
				height: 30px;
				line-height: 30px;
				font-family: "黑体";
				font-size: 0.9em;
			}
			/*提示窗的标题*/
			
			.BMap_bubble_title {
				text-align: center;
				font-weight: bold;
			}
		</style>
		<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=MMh4H9m5FLBpizlht86GnGynuaM0oGKz"></script>
	</head>

	<body ontouchstart>
		<div class="mask opacity" id="opacityDiv" style="display: none;"></div>
		<div id="line_main">
			<div class="index_head" id="firTitle">
				<div class="app_head_left">
					<a id="busReturnBtn" onclick="busReturnBtn()" class="iconfont">&#xe6d4;</a>
				</div>
				<div class="app_head_mid">
					<p id="app_head_title">公交查询</p>
				</div>
				<div class="app_head_right">
					<a href="javascript:;" class="iconfont" id="JLcitySelect">长春 &#xe6d5;</a>
				</div>
			</div>

			<div class="weui_tab" id="line_mid">
				<div class="sec_line">
					<div id="InputLine">
						<a href="javascript:;" id="cxLineBtn" class="btnInInput" onclick="showWhichInput(this)">
							<img src="img/bus/InputlineIcon.png" />查询线路
						</a>
						<a href="javascript:;" class="btnInInput" onclick="showWhichInput(this)">
							<img src="img/bus/InputStopIcon.png" />查询站点
						</a>
						<input type="text" class="suggestId" id="suggestId_line" size="20" placeholder="请输入线路名称" style="display: none;" onfocus="focusJumpToMap()" />
						<input type="text" class="suggestId" id="suggestId_stop" size="20" placeholder="请输入站点名称" style="display: none;" onfocus="focusJumpToMap()" />
						<input type="hidden" id="hidden_suggestId" value="" />
						<ul id="busSelectUl_ts" style="display: none;">

						</ul>
						<!--<a id="delBtn" href="javascript:;" class="iconfont" style="display: none;">&#xe60b;</a>-->
						<a id="searchBtn" href="javascript:;" class="iconfont" style="display: none;">&#xe709;</a>
					</div>
				</div>
				<!--选择步行公交自驾按钮区域-->
				<div class="weui_navbar" id="secTitle">
					<a href="#line" class="weui_navbar_item weui_bar_item_on" id="chooseLine"><b>地图&线路</b></a>
					<a href="#station" class="weui_navbar_item" id="chooseStation"><b>详情&站点</b></a>
				</div>
				<div class="weui_tab_bd" id="searchResultArea">
					<div id="line" class="weui_tab_bd_item weui_tab_bd_item_active">
						<div id="allmap"></div>
					</div>
					<div id="station" class="weui_tab_bd_item">
						<!--loading图标-->
						<div class="loadingImgResult" id="loadingTb" style="display: none;">
							<div class="loading">
								<span>畅</span>
								<span>行</span>
								<span>吉</span>
								<span>林</span>
							</div>
							<!--<label>数据查询中</label>-->
						</div>
						<!--百度查询结果-->
						<div id="r-result" style="display: none;"></div>
						<!--英辰数据查询结果-->
						<div id="ycDataResult" style="display: none;">
							<div class="ycResult_title">
								<p class="ycResult_title_left" style="width: 40%;"><span id="lineName" class="busDataCss"></span>路</p>
								<p class="ycResult_title_right" style="width: 60%; text-align: right;">
									开往<span id="toEnd" class="busDataCss"></span>方向
								</p>

								<p style="width: 33%;">
									全程<span id="line_length" class="busDataCss"></span>公里
								</p>
								<p style="width: 24%;">
									票价<span id="line_price" class="busDataCss"></span>元
								</p>
								<p style="width: 43%; text-align: right;">
									<span id="line_self" style="font-size: 1em"></span>人售票&nbsp;&nbsp;月票<span id="line_mon" style="font-size: 1em"></span>效
								</p>
								<p class="ycResult_title_left" style="width: 70%;">
									<!--<span id="line_time"></span>-->
									<a href="javascript:;" class="timeIconA" id="timeIcon" data-msg=""><img src="img/bus/FLbusTime.png" class="FL_Icon" />点击查看首末班时刻</a>
								</p>
								<p style="width: 30%;">
									<a href="javascript:;" id="hxBtn"><img src="img/bus/changeshuangxiang.png" />换向</a>
								</p>
								<ul id="stopUl">
									<!--<li>1. 长春站<img src="img/bus/subwayBtn.png" class="nearbySubwayIcon"/>带有附近地铁标志的</li>-->
									<!--调取 添加DOM-->
								</ul>

							</div>
						</div>
						<!--公交站点数据展示区域-->
						<div id="busStopArea" style="display: none;">
							<div id="busStopTitle">
								<span id="stopName"></span><b class="ml5">站</b>
							</div>
							<div id="address">
								<b>地址：</b>
								<span id="stopAddress"></span>
							</div>
							<div data-address="" data-x="" data-y="" style="color: #41AF2B; font-size: 17px;" id="stopJumpToMap" onclick="busStopMap(this)">
								<a class="iconfont" style="color: #41AF2B; font-size: 1.35em;">&#xe6c9;</a>到地图上查看
							</div>
							<div id="allBusline">
								<b>本站公交：</b><span id="stopBusLine"></span>
							</div>
						</div>
						<!--<img src="img/taxi/loading_icon.gif" class="loadingSFZ" id="loadingSFZ" style="display: none;" />-->
						<h1 class="noResult" id="noResult">请输入查询信息</h1>
						<h1 class="noResult" id="noResult2" style="display: none;">本线路暂无数据</h1>
					</div>
				</div>
			</div>
			<footer>
				<li>
					<a id="btn_ditu" onclick="clickBottom(this)">
						<img src="img/bus/chooseBusMap.png" style="width: 30px;" id="mapPage1" />
						<img src="img/bus/bus_map.png" style="width: 30px; display: none;" id="mapPage2" />
						<label id="lable_map">地图<label>
				   </a>
			    </li>
				<li>
					<a id="btn_xiangqing" onclick="clickBottom(this)">
						<img src="img/bus/chooseBusmsg.png" style="width: 30px; display: none;" id="msgPage1" />
						<img src="img/bus/bus_msg.png" style="width: 30px;" id="msgPage2"/>
						<label id="lable_msg">详情<label>
				    </a>
			    </li>
			</footer>
		</div>
		<script src="js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/back_end.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/weui/jquery-weui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//          获取路线信息
var dsq = false;
var clicktag = 0; //设置按钮点击默认值0
var updown = 1;
var dataType = "";

//底部点击事件
function clickBottom(t) {
	if($(t).html().indexOf("地图") > -1) { //点击地图
		if(!$("#lable_map").hasClass("chooseMapOrMsg") && document.getElementById("ycDataResult").style.display == "block") {
			getBusMsg(updown);
		}
		$("#chooseLine").click();
		$("#msgPage2").show();
		$("#msgPage1").hide();
		$("#mapPage2").hide();
		$("#mapPage1").show();
		$("#lable_map").addClass("chooseMapOrMsg");
		$("#lable_msg").removeClass("chooseMapOrMsg");
	} else { //点击详情
		$("#chooseStation").click();
		$("#msgPage1").show();
		$("#msgPage2").hide();
		$("#mapPage1").hide();
		$("#mapPage2").show();
		$("#lable_msg").addClass("chooseMapOrMsg");
		$("#lable_map").removeClass("chooseMapOrMsg");
	}
}

//点击显示哪个输入框
function showWhichInput(t) {
	$(".btnInInput").hide();
	$("#searchBtn").fadeIn(400);
	if(t.innerHTML.indexOf("查询线路") > -1) {
		$("#suggestId_line").fadeIn(400);
		$("#InputLine").addClass("lineStyle");
	} else if(t.innerHTML.indexOf("查询站点") > -1) {
		$("#suggestId_stop").fadeIn(400);
		$("#InputLine").addClass("stopStyle");
	}
}

//返回按钮
function busReturnBtn() {
	$("#busSelectUl_ts").hide();
	if($("#line").hasClass("weui_tab_bd_item_active")) {
		if(document.getElementById("searchBtn").style.display == "none") {
			window.location.href = "javascript:history.go(-1)";
		} else {
			$(".suggestId").val("");
			$(".suggestId").hide(); //隐藏输入框和查询按钮
			$("#searchBtn").hide();
			$(".btnInInput").fadeIn(400); //显示两个按钮
			$("#InputLine").removeClass("lineStyle").removeClass("stopStyle");
		}
	} else if($("#station").hasClass("weui_tab_bd_item_active")) {
		$("#btn_ditu").click();
	}
}

//输入框的focus事件
function focusJumpToMap() {
	if($("#station").hasClass("weui_tab_bd_item_active")) { //当页面在详情位置时，输入框获得焦点 则跳回地图
		$("#btn_ditu").click();
	};
}

//切换城市
$("#JLcitySelect").select({
	title: "切换城市 畅行吉林",
	items: [{
		title: "长春",
		value: "长春",
	}, 
//	{
//		title: "松原",
//		value: "松原",
//	}
	],
	onOpen: function() {
		//弹窗打开时 显示遮罩层
		$("#opacityDiv").show();
	},
	onClose: function() {
		//弹窗打开时 显示遮罩层
		$("#opacityDiv").hide();
	},
	onChange: function(d) {
		$("#JLcitySelect").html(d.titles + " &#xe6d5;");
		$("#opacityDiv").hide();
		if(d.titles == "松原") {
			//						$.alert("对不起，该城市暂无数据", "提示", function() {
			//							d.titles = "长春";
			//							$("#JLcitySelect").html("长春" + " &#xe6d5;");
			//						})

			var syP = new BMap.Point(124.818259, 45.165914);
			map.centerAndZoom(syP, 12);
		} else if(d.titles == "长春") {
			var P = new BMap.Point(125.330855, 43.936976);
			map.centerAndZoom(P, 12);
		}
		$("#btn_ditu").click();
		$("#InputLine input").val("");
		$("#station div").hide();
		$("#station h1").show();
	}
});

$(function() {
	$("#lable_map").addClass("chooseMapOrMsg");
	$("#hidden_suggestId").val(""); //清空隐藏input框
	var h = document.documentElement.clientHeight - 130 - 50;
	$("#allmap").height(h);
	$("#station").height(h);
	//设置模糊查询提示框宽度
	$("#busSelectUl_ts").width($("#InputLine").width() - 30);
	//通过站点上的公交查询线路
	var urlStr = "" + window.location;
	if(urlStr.indexOf("?line") > -1) {
		var line = urlStr.split("?line=")[1];
		line = decodeURI(line);
		//		console.log(line);
		$("#cxLineBtn").click();
		$("#suggestId_line").val(line);
		setTimeout(function() {
			$("#searchBtn").click(); //查询这条线路
		}, 300);
	}

});

$(".weui_navbar_item").click(function() {
	$("#busSelectUl_ts").html(""); //清空提示框的所有信息
	$("#busSelectUl_ts").hide(); //并隐藏 
});

// 百度地图API功能
var map = new BMap.Map("allmap");
var P = new BMap.Point(125.330855, 43.936976);
map.centerAndZoom(P, 12);

var busline = new BMap.BusLineSearch(map, {
	renderOptions: {
		map: map,
		panel: "r-result"
	},
	onGetBusListComplete: function(result) {
		if(result) {
			var fstLine = result.getBusListItem(0); //获取第一个公交列表显示到map上
			busline.getBusLine(fstLine);
		}
	}
});

//点击查询放大镜按钮
$("#searchBtn").click(function() {
	if($("#suggestId_line").val() == "" && $("#suggestId_stop").val() == "") {
		
	} else {
		dsq = true;
		$("#station div").show();
		//				if(document.getElementById("busSelectUl_ts").style.display!="none"){
		$("#busSelectUl_ts").hide();
		if($("#suggestId_line").val() != "") {
			$("#station").children().hide();
			$("#ycDataResult").show();
			//			map.setZoom(14);
			//			busSearch();//百度查询线路方法
			//获取公交线路查询信息
			getBusMsg(0);
		} else if($("#suggestId_stop").val() != "") { //查询站点
			$("#station").children().hide();
			$("#busStopArea").show();
			if($("#hidden_suggestId").val() == "") {
				//当隐藏input无值时 提示请用户输入信息keyup
				$.alert("请您输入正确的公交站名", "提示");
			} else {
				getBusStopMsg();
			}
		}
	}
	//				}
});

//获取公交站点查询信息
function getBusStopMsg(area) {
	var area = "";
	var cityStr = $("#JLcitySelect").html();
	if(cityStr.indexOf("长春") != -1) {
		area = "cc";
		getStopMsgAjax(area);
	} else if(cityStr.indexOf("松原") != -1) {
		area = "sy";
		getStopMsgAjax(area);
	}

};

//获取公交线路信息
function getBusMsg(updown) {
	var area = "";
	var cityStr = $("#JLcitySelect").html();
	if(cityStr.indexOf("长春") != -1) {
		area = "cc";
		getMsgAjax(area, updown);
	} else if(cityStr.indexOf("松原") != -1) {
		area = "sy";
		getMsgAjax(area, updown);
	}
}

//获取公交站点信息 ajax 方法
function getStopMsgAjax(area) {
	$.ajax({
		type: "post",
		url: Url,
		data: {
			"type": "bus_station_query_info", //获取公交站点查询信息
			"STATIONGUID": $("#hidden_suggestId").val(), //这个公交站点的唯一GUID值
			"AREA": area
		},
		async: false,
		cache: false,
		dataType: "jsonp", //数据类型为jsonp
		jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
		jsonpCallback: "jsonpCallback1",
		success: function(data) {
			//						console.log(data);
			if(data.MSG == "失败") {
				$("#noResult").show();
			} else {
				var d = data.DATA;
				var m = data.MDATA;
				if(isEncrypt(d, m)) {
					var stopObj = eval(d)[0];
					var stopName = stopObj.STATIONNAME;
					stopName = yzStationStr(stopName);
					var stopX = stopObj.LATITUDELOCATIONOFSTATION;
					var stopY = stopObj.LONGITUDELOCATIONOFSTATION;
					var addressStr = stopObj.ROADNAMEOFSTATIONLOCATED.split(",");
					var busLineStr = stopObj.LINENAME.split(",");
					var address = ""; //地址字符串
					var busLine = ""; //途径本站公交循环添加
					for(var i = 1; i < addressStr.length; i++) {
						address += addressStr[i] + "";
					}
					for(var i = 0; i < busLineStr.length; i++) {
						busLine += "<li onclick='searchLineFromStop(this)'>" + busLineStr[i] + "路</li>";
						if(area == "sy") {
							busLine = busLine.replace("路路", "路");
						}
					}

					//								console.log(stopName);
					$("#stopName").html(stopName);
					$("#stopAddress").html(address);
					$("#stopJumpToMap").attr("data-x", stopX).attr("data-y", stopY);
					$("#stopBusLine").html(busLine);
					$("#btn_xiangqing").click(); //跳转至详情
				} else {
					errMD();
				}

			}
		},
		error: function(data) {
			$.alert("连接超时，请重试", "提示");
		}
	});
}

//获取公交信息 调取ajax方法
function getMsgAjax(area, updown) {
	//获取公交线路查询信息
	$.ajax({
		type: "post",
		url: Url,
		data: {
			"type": "bus_line_query_info",
			"LINECODE": $("#suggestId_line").val(),
			"UPDOWN": updown, //上下行 0或1
			"AREA": area
		},
		async: false,
		cache: false,
		dataType: "jsonp", //数据类型为jsonp
		jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
		jsonpCallback: "jsonpCallback1",
		success: function(data) {
			map.clearOverlays(); //清空地图上的所有覆盖物
//			console.log(data.MSG);
			if(data.MSG == "失败") {
				$("#station div").hide();
				$("#noResult2").show();
//				$(".weui_dialog_bd");
				$.alert("本线路暂无数据","提示",function(){
					
				});
			} else {
				var d = data.DATA;
				var m = data.MDATA;
				console.log(d);
				if(isEncrypt(d, m)) {
//					console.log(d);
					$("#loadingTb").hide(); //隐藏loading图标
					$("#ycDataResult").show(); //显示英辰数据
					//						console.log(data.DATA);
					$("#stopUl").html(""); //清空本线路站名列表
					$("#ycDataResult").show(); //显示详情&站点数据
					var lineData = JSON.parse(d);
					var busInfo = lineData.stationInfoArray;//站点
					var busPathInfo = lineData.coordinateArray;
					var newPathArray = []; //在地图上所有站点的点集合
					var name = lineData.LINENAME; //名称
					var ll = lineData.LINELENGTH; //里程
					var time = lineData.DEPARTURE_TIME; //发车时间
					var price = lineData.NORMALWHOLETRIPFARE; //票价
					var mon = lineData.IS_MONTHLY_TICKET; //0：月票无效 ，1：月票有效
					mon == 0 ? mon = "无" : mon = "有";
					var self = lineData.IS_SELF_TICKETING; //1:无人售票，0：有人售票
					self == 1 ? self = "无" : self = "有";
					var msgArr = lineData.stationInfoArray
					var end = msgArr[msgArr.length - 1].STATIONNAME;
					end = yzStationStr(end); //开往的终点站名称 去除结尾数字
					//						console.log(msgArr[1].STATIONNAME);
					for(var i = 0; i < msgArr.length; i++) {
						var n = msgArr[i].STATIONNAME; //名称
						var positionX = msgArr[i].LATITUDELOCATIONOFSTATION;
						var positionY = msgArr[i].LONGITUDELOCATIONOFSTATION; //站点经纬度
						var stationName = msgArr[i].STATIONNAME; //站点名称
						var address = msgArr[i].ROADNAMEOFSTATIONLOCATED; //站点具体地址
						stationName = yzStationStr(stationName); //去除结尾数字
						var li = $('<li data-name="' + n + '" data-pX="' + positionX + '" data-pY="' + positionY + '" data-address="' + address + '" onclick="stationMainSearch(this)">' + (i + 1) + '. ' + stationName + '</li>');
						var cityStr = $("#JLcitySelect").html();
						if(cityStr.indexOf("长春") > -1) {
							if(msgArr[i].nearStation != "") {
								//该站附近有地铁
								var subwayIcon = $('<img src="img/bus/subwayBtn.png" class="nearbySubwayIcon"/>');
								$(li).append(subwayIcon);
							}
						}
						if(i < 9) {
							$(li).css("margin-left", "5px");
						}
						$("#stopUl").append(li);
					}
					//循环添加所有点集合到空数组中
					for(var s = 0; s < busPathInfo.length; s++) {
						var c = busPathInfo[s];
						var a = Number(c.LAITITUDE);
						var b = Number(c.LONGITUDE);
						newPathArray.push(new BMap.Point(b, a))
					}
					//创建折线	
					var polyline = new BMap.Polyline(newPathArray, {
						enableEditing: false, //是否启用线编辑，默认为false
						enableClicking: true, //是否响应点击事件，默认为true
						strokeWeight: '8', //折线的宽度，以像素为单位
						strokeOpacity: 0.8, //折线的透明度，取值范围0 - 1
						strokeColor: "#18a45b" //折线颜色
					});
					map.addOverlay(polyline);
					//让线路试应屏幕
					map.setViewport(newPathArray);

					//地图上创建用户查询这条线路的所有公交站点
					var blength = busInfo.length;
					var tag = '';
					for(var i = 0; i < blength; i++) {
						busInfo[i].STATIONNAME = yzStationStr(busInfo[i].STATIONNAME);
						var content = "<p class='cb fb f16 mb10' style='text-align:center;'>" + busInfo[i].STATIONNAME + "</p>" +
							"<p class='mb10' style='text-align:left;'>" + busInfo[i].ROADNAMEOFSTATIONLOCATED.replace(/,/g, "") + "</p>"; //站点具体地址;
						var daozhequ = busInfo[i].LONGITUDELOCATIONOFSTATION + "," + busInfo[i].LATITUDELOCATIONOFSTATION;
						var crossLine = busInfo[i].crossLine.replace(/,/g,'； ');
						//跳转出行规划
						content += '<div class="tzdcx" style="text-align: center;" ></div><span>本站所有公交：'+ crossLine + '<span/>';
//							'<a onclick="tzdcxgh(this);" data-sta="' + busInfo[i].STATIONNAME + "!" + busInfo[i].ROADNAMEOFSTATIONLOCATED.replace(/,/g, "") + '" name="' + daozhequ + '" style="outline-style: none;letter-spacing: 2px;width: 80px" type="button" id="goHearBtn" class="weui_btn weui_btn_primary" >到这去</a>' +
							
						//创建公交站点
						var point1 = new BMap.Point("" + busInfo[i].LONGITUDELOCATIONOFSTATION + "", "" + busInfo[i].LATITUDELOCATIONOFSTATION + "");
						//创建图标
						var taxiIcon;
						taxiIcon = new BMap.Icon("img/bus/pic_zhandianyuan.png", new BMap.Size(14, 14));
						//										}
						var marker1 = new BMap.Marker(point1, {
							icon: taxiIcon
						}); // 创建标注
						map.addOverlay(marker1);

						addClickHandler(content, marker1);
					}
				}
				$("#lineName").html(name);
				$("#toEnd").html(end);
				$("#line_length").html(ll);
				$("#line_price").html(price);
				$("#line_self").html(self);
				$("#line_mon").html(mon);
				$("#timeIcon").attr("msg", time);

				clearTimeout(timeout);
				timeout = setTimeout(function() {
					getGpsMsg(updown);
				}, 500); //公交线路调取成功后 执行调取GPS信息
			}
		},
		error: function(data) {
			$.alert("连接超时，请重试", "提示");
		}
	});
}

//点击换向 重新请求
$("#hxBtn").click(function() {
	if(clicktag == 0) {
		$("#loadingTb").show(); //显示loading图标
		$("#ycDataResult").hide(); //隐藏英辰数据div
		clicktag = 1; //将标注改为1 当标注为1时换向按钮失效
		if(updown == 0) {
			updown = 1;
			//			console.log(updown);
			getBusMsg(1);
		} else {
			updown = 0;
			//			console.log(updown);
			getBusMsg(0);
		}

		setTimeout(function() {
			clicktag = 0
		}, 1000); //防止按钮被2秒内被连续恶意点击
	} else {
		$.alert("操作过于频繁，请稍等", "温馨提示", function() {
			$(".weui_dialog_bd").removeClass("h40");
		});
		$(".weui_dialog_bd").addClass("h40");
	}
});

//点击每个站名跳转至地图并弹出详细信息方法
function stationMainSearch(t) {
	$("#btn_ditu").click();
	setTimeout(function() {
		var n = $(t).attr("data-name");
		var pX = $(t).attr("data-pX");
		var pY = $(t).attr("data-pY");
		var dzq = pX + "," + pY;
		var thisPoint = new BMap.Point(pY, pX);
		var dizhi = $(t).attr("data-address").replace(/,/g, "");
		var dz = dizhi;
//		+ '<a onclick="tzdcxgh(this);" data-sta="'+ yzStationStr(n) +"!" + dizhi + '" name="' + dzq + '" style="outline-style: none;letter-spacing: 2px;width: 80px" type="button" id="goHearBtn" class="mt15 weui_btn weui_btn_primary" >到这去</a>';
		//				console.log(pX);
		var marker = new BMap.Marker(thisPoint); // 创建标注
		//		 // 将标注添加到地图中
		var centerP = thisPoint;
		map.centerAndZoom(centerP, 13);
		//	var content = "<p class='cb fb f16 mb10' style='text-align:center;'>" + n + "</p>" +
		//		"<p class='mb10' style='text-align:center;'>" + dz + "</p>"; //站点具体地址;
		//	console.log(content);
		var opts = {
			width: 150, // 信息窗口宽度
			title: yzStationStr(n), // 信息窗口标题
			enableMessage: true //设置允许信息窗发送短息
		}
		var infoWindow = new BMap.InfoWindow(dz, opts); // 创建信息窗口对象
		marker.setOffset(new BMap.Size(4, 22)); //改变提示文本位置
		map.openInfoWindow(infoWindow, thisPoint); //页面跳转至地图区域自动开启信息窗口
		marker.addEventListener("click", function(e) {
			map.openInfoWindow(infoWindow, centerP); //开启信息窗口
			//					this.openInfoWindow(e.target.infoWindow); 
		});
		map.centerAndZoom(centerP, 13);
		//				map.setCenter(centerP);
		//	map.enableInertialDragging(); //开启惯性拖拽
		//信息加载完成后 跳转至地图区域

	}, 500);
}

//获取对话框中首末班信息方法
function getFLMsg() {
	//				var ul1 = $('<ul class="msg_ul"></ul>');
	//				var ul2 = $('<ul class="msg_ul"></ul>');
	var arr = $("#timeIcon").attr("msg").split(",");
	//				console.log(arr);
	var SumLi = "";
	var WinLi = "";
	for(var i = 0; i < 4; i++) {
		SumLi += '<li>' + arr[i] + '</li>';
	}
	//				console.log(SumLi);
	for(var i = 4; i < 8; i++) {
		WinLi += '<li>' + arr[i] + '</li>';
	}
	return '<ul class="msg_ul">' + SumLi + '</ul>' + '<ul class="msg_ul">' + WinLi + '</ul>';
}
$("#timeIcon").click(function() {
	$.alert(getFLMsg(), "首末班情况");
});

//判断字符串结尾是否为数字
function yzStationStr(str) {
	var endStr = str.substr(str.length - 1, 1);
	var n = Number(endStr);
	if(!isNaN(n)) {
		str = str.substr(0, str.length - 1); //将结尾的数字去掉
	}
	return str;
};

function busSearch() {
	var busName = $("#suggestId_line").val();
	busline.getBusList(busName); //百度请求公交线路详情方法
};

var timeout;
//线路输入框
$("#suggestId_line").keyup(function() {
	if($(this).val() == "") {
		//当输入框为空的时候 不执行
		$("#busSelectUl_ts").hide();
	} else {
		dataType = "bus_line_info";
		//延时请求 验证所输入地点是否已收藏
		clearTimeout(timeout);
		timeout = setTimeout("Line(dataType)", 500);
	}

});

//站点输入框
$("#suggestId_stop").keyup(function() {
	if($(this).val() == "") {
		//当输入框为空的时候 不执行
		$("#busSelectUl_ts").hide();
	} else {
		$("#noResult").hide(); //隐藏查询无结果字样
		dataType = "bus_station_info";
		//延时请求 验证所输入地点是否已收藏
		clearTimeout(timeout);
		timeout = setTimeout("Stop(dataType)", 500);
	}
});

//ajax验证请求方法
function Line(dataType) {
	var area = ""; //定义查询的城市名为变量
	var cityStr = $("#JLcitySelect").html();
	if(cityStr.indexOf("长春") != -1) { //当选择城市定为长春时
		if($("#suggestId_line").val() == "") {
			//当输入框为空的时候 不执行
		} else {
			area = "cc";
			LineAjax(area);
		}
	} else if(cityStr.indexOf("松原") != -1) { //松原市
		if($("#suggestId_line").val() == "") {
			//当输入框为空的时候 不执行
		} else {
			area = "sy";
			LineAjax(area);
		}
	}
};

//ajax验证请求方法
function Stop(dataType) {
	var area = ""; //定义查询的城市名为变量
	var cityStr = $("#JLcitySelect").html();
	if(cityStr.indexOf("长春") != -1) { //当选择城市定为长春时
		if($("#suggestId_stop").val() == "") {
			//当输入框为空的时候 不执行
		} else {
			area = "cc";
			StopAjax(area);
		}
	} else if(cityStr.indexOf("松原") != -1) { //松原市
		if($("#suggestId_stop").val() == "") {
			//当输入框为空的时候 不执行
		} else {
			area = "sy";
			StopAjax(area);
		}
	}
};
//线路调取ajax 方法
function LineAjax(area) {
	$.ajax({
		type: "post",
		url: Url,
		data: {
			"type": dataType,
			"LINECODE": $("#suggestId_line").val(),
			"STATIONNAME": $("#suggestId_line").val(),
			"AREA": area //区域代号
		},
		async: false,
		cache: false,
		dataType: "jsonp", //数据类型为jsonp
		jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
		jsonpCallback: "jsonpCallback1",
		success: function(data) {
			//							console.log(data);
			$("#busSelectUl_ts").html("");
			//						console.log(data.MSG);
			if(data.CODE == 0) {
				$("#busSelectUl_ts").hide();
			} else {
				var d = data.DATA;
				var m = data.MDATA;
				if(isEncrypt(d, m)) {
					d = eval(d);
					for(var i = 0; i < d.length; i++) {
						if(d[i].ROUTE_NAME) {
							var n = d[i].ROUTE_NAME;
						} else {
							var n = d[i].STOP_NAME;
						}

						//						console.log(n);
						//						if(n.indexOf(""))
						var li = $('<li onclick="chooseThisMain(this)">' + n + '</li>');
						if(eval(data.DATA).length > 6) {
							//如果模糊查询结果过多 设置ul高度最大为250px
							$("#busSelectUl_ts").height(250);
							$("#busSelectUl_ts").css("overflow-y", "auto");
						} else {
							$("#busSelectUl_ts").css("height", "auto");
						}
						$("#busSelectUl_ts").append(li);
						$("#busSelectUl_ts").show();
					}
				}

			}
		},
		error: function(data) {
			$.alert("连接超时，请重试", "提示");
		}
	});
}
//站点模糊查的ajax
function StopAjax(area) {
	$.ajax({
		type: "post",
		url: Url,
		data: {
			"type": dataType,
			"STATIONNAME": $("#suggestId_stop").val(),
			"AREA": area //区域代号
		},
		async: false,
		cache: false,
		dataType: "jsonp", //数据类型为jsonp
		jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
		jsonpCallback: "jsonpCallback1",
		success: function(data) {
			//						console.log(data);
			$("#busSelectUl_ts").html("");
			if(data.MSG == "失败") {
				$("#busSelectUl_ts").hide();
			} else {
				var d = data.DATA;
				var m = data.MDATA;
				var num = data.COUNT;
				if(isEncrypt(d, m)) {
					var stationArr = eval(d);
					$("#hidden_suggestId").val(stationArr[0].STOP_GUID); //如果用户未点击li进行查询，直接点击放大镜查询 则默认取li第一个Guid来查询公交站点信息
					for(var i = 0; i < stationArr.length; i++) {
						var stopName = stationArr[i].STATIONNAME;
						stopName = yzStationStr(stopName);
						var stopGUID = stationArr[i].STOP_GUID;
						var addressStr = stationArr[i].ROADNAMEOFSTATIONLOCATED;
						var addressArr = addressStr.split(","); //处理地址字符串结构
						var stopAddress = "";
						for(var j = 1; j < addressArr.length; j++) {
							stopAddress += addressArr[j];
						}
						
						var li = $('<li class="busStopLi" data-Guid="' + stopGUID + '" onclick="chooseThisBusStop(this)"><a class="busStopName">' + stopName + '</a>' + stopAddress + '</li>');
						if(eval(data.DATA).length > 6) {
							//如果模糊查询结果过多 设置ul高度最大为250px
							$("#busSelectUl_ts").height(225);
							$("#busSelectUl_ts").css("overflow-y", "auto");
						} else {
							$("#busSelectUl_ts").css("height", "auto");
						}
						$("#busSelectUl_ts").append(li);
						$("#busSelectUl_ts").show();

					}
				} else {
					errMD();
				}
			}
		},
		error: function(data) {
			$.alert("连接超时，请重试", "提示");
		}
	});
};

//模糊查询线路提示框选择点击事件
function chooseThisMain(tt) {
	$("#suggestId_line").val(tt.innerHTML);
	$("#busSelectUl_ts").hide();
	$("#searchBtn").click();
};

//模糊查询点击方法 ：按站点查询
function chooseThisBusStop(ss) {
	$("#suggestId_stop").val($(ss).children().html());
	$("#hidden_suggestId").val($(ss).attr("data-Guid"));
	$("#busSelectUl_ts").hide();
	$("#searchBtn").click();
}

function getDSQ(){
	var areaStr = "cc_bus_gps_info";
	if(updown==1){
		getGpsAjax(0, areaStr);
	}else if(updown==0){
		getGpsAjax(1, areaStr);
	}
};

var timeOut ;
function time() {
	if(dsq) return;
	getDSQ();
	clearTimeout(timeOut);
	timeOut=setTimeout(function() {
		time();
	}, "10000"); //实时刷新 10秒一次
		
}


//获取公交GPS信息
function getGpsMsg(updown) {
	var areaStr = ""; //定义查询的城市名为变量
	var cityStr = $("#JLcitySelect").html();
	if(cityStr.indexOf("长春") != -1) { //当选择城市定为长春时
		areaStr = "cc_bus_gps_info"; //长春市公交GPS字段名
		getGpsAjax(updown, areaStr);//IOS版本上线暂时注释
		dsq = false;
		time(); //IOS版本上线暂时注释;
	} else if(cityStr.indexOf("松原") != -1) {
		areaStr = "sy_bus_gps_info"; //松原市公交GPS字段名
//		getGpsAjax(updown, areaStr);//IOS版本上线暂时注释
		//~~~~~~~~~~~~~~~~~
	}

}

var i = 0;
var markerBus;
var markerBusArr = [];
//获取公交GPS 调取ajax方法
function getGpsAjax(updown, areaStr) {
	//	i++;
	//	console.log(i);
	$.ajax({
		type: 'post',
		url: "http://111.26.219.36:9595/jt809a-gongjiao/cc",
		async: false,
		cache: false,
		data: {
			type: areaStr,
			LINECODE: $("#suggestId_line").val(),
			GPSUPDOWN: updown
		},
		dataType: "jsonp", //数据类型为jsonp
		jsonp: "callbackparam", //服务端用于接收callback调用的function名的参数  
		jsonpCallback: "jsonpCallback1",
		success: function(data) {
			//						console.log(data);
			if(data.MSG == "成功") {
				var d = data.DATA;
				var m = data.MDATA;
				if(isEncrypt(d, m)) {
					if(markerBusArr.length != 0){
						
						for (var i = 0;i < markerBusArr.length;i++) {
							map.removeOverlay(markerBusArr[i]);
						}
					}			
					markerBusArr=[];

					//map.removeOverlay(markerBus);
					//					console.log("点的数量："+ $(".BMap_Marker[title='公交车']").length);
//					$("span[title='公交车']").remove(); //清空所有线上的公交车图标
					d = eval(d);
					for(var i = 0; i < d.length; i++) {
						var direction = d[i].fangxiang; //方向角
						var x = d[i].jiupianjingdu;
						var y = d[i].jiupianweidu;
						var info = d[i].chepaihao;
						var point1 = new BMap.Point(x, y);
						//创建图标
						var taxiIcon = new BMap.Icon("img/bus/bus_getfx.png", new BMap.Size(20, 38));
						markerBus = new BMap.Marker(point1, {
							icon: taxiIcon,
							title: "公交车"
						}); // 创建标注
						markerBus.setZIndex(999);//层级
						
						markerBusArr.push(markerBus);//推入数组
						
						markerBus.setRotation(direction);//方向角
						//						markerBus.setOffset(new BMap.Size(0, -7));
						map.addOverlay(markerBus);//添加点
						var content = "<p style='text-align:center;color:#0070b4;font-size:16px;'>" + info + "</p >";

						addClickHandler(content, markerBus);
					}
				} else {
					errMD();
				}

			}

		}
	});
}

function addClickHandler(content, marker) {
	marker.addEventListener("click", function(e) {
		openInfo(content, e);
	})
}

function openInfo(content, e) {
	var p = e.target;
	var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
	var infoWindow = new BMap.InfoWindow(content, ""); // 创建信息窗口对象
	map.openInfoWindow(infoWindow, point); //开启信息窗口
}

//站点： 点击到地图查看
function busStopMap(t) {
	$("#btn_ditu").click();
	var x = $(t).attr("data-x");
	var y = $(t).attr("data-y");

	setTimeout(function() {
		var stopPoint = new BMap.Point(y, x);
		var stopMarker = new BMap.Marker(stopPoint);
		map.centerAndZoom(stopPoint, 17);
		map.addOverlay(stopMarker);
		var opts = {
			width: 100, // 信息窗口宽度
			//						height: 80,
			title: $("#stopName").html() + "<br/>本站公交：<br/>" + $("#stopBusLine").html(), // 信息窗口标题
			enableMessage: true //设置允许信息窗发送短息
		}
		var infoWindow = new BMap.InfoWindow("", opts); // 创建信息窗口对象
		stopMarker.setOffset(new BMap.Size(4, 22)); //改变提示文本位置
		map.openInfoWindow(infoWindow, stopPoint); //页面跳转至地图区域自动开启信息窗口
		stopMarker.addEventListener("click", function(e) {
			map.openInfoWindow(infoWindow, stopPoint); //开启信息窗口
			this.openInfoWindow(e.target.infoWindow);
		});
		map.enableInertialDragging();
	}, 500);
	//				map.centerAndZoom(stopPoint,18);			
}

//通过查询站点的本站公交反查线路
function searchLineFromStop(t) {
	var searchStr = t.innerHTML;
	if($("#JLcitySelect").html().indexOf("长春") > -1) {
		searchStr = searchStr.replace("路", "");
		window.location.href = "cxgh_line.html?line=" + searchStr;
	}

}

//弹框中“到这去”跳转出行规划功能
function tzdcxgh(t) {
	var pointStr = $(t).attr("data-sta");
	console.log(pointStr);
	var url = "cxgh.html?bus=" + pointStr;
	url = encodeURI(url);
	window.location.href = url;
}
		</script>
	</body>

</html>